home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / whdload / include / whdmacros.i < prev   
Text File  |  2000-02-28  |  7KB  |  329 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Module.    whdmacros.i
  3. ;  :Contens.    useful macros for WHDLoad-Slaves
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@whdload.org
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: whdmacros.i 10.5 2000/01/25 22:09:38 jah Exp jah $
  8. ;  :History.    11.04.99 separated from whdload.i
  9. ;  :Copyright.    © 1996-2000 Bert Jahn, All Rights Reserved
  10. ;  :Language.    68000 Assembler
  11. ;  :Translator.    Barfly V2.9
  12. ;---------------------------------------------------------------------------*
  13.  
  14.  IFND WHDMACROS_I
  15. WHDMACROS_I=1
  16.  
  17.     IFND    HARDWARE_CIA_I
  18.     INCLUDE    hardware/cia.i
  19.     ENDC
  20.     IFND    HARDWARE_CUSTOM_I
  21.     INCLUDE    hardware/custom.i
  22.     ENDC
  23.     IFND    HARDWARE_INTBITS_I
  24.     INCLUDE    hardware/intbits.i
  25.     ENDC
  26.     IFND    HARDWARE_DMABITS_I
  27.     INCLUDE    hardware/dmabits.i
  28.     ENDC
  29.  
  30. ;=============================================================================
  31.  
  32.  BITDEF POTGO,OUTRY,15
  33.  BITDEF POTGO,DATRY,14
  34.  BITDEF POTGO,OUTRX,13
  35.  BITDEF POTGO,DATRX,12
  36.  BITDEF POTGO,OUTLY,11
  37.  BITDEF POTGO,DATLY,10
  38.  BITDEF POTGO,OUTLX,9
  39.  BITDEF POTGO,DATLX,8
  40.  BITDEF POTGO,START,0
  41.  
  42. _ciaa        = $bfe001
  43. _ciab        = $bfd000
  44. _custom        = $dff000
  45.  
  46. ****************************************************************
  47. ***** write opcode ILLEGAL to specified address
  48. ill    MACRO
  49.     IFNE    NARG-1
  50.         FAIL    arguments "ill"
  51.     ENDC
  52.         move.w    #$4afc,\1
  53.     ENDM
  54.  
  55. ****************************************************************
  56. ***** write opcode RTS to specified address
  57. ret    MACRO
  58.     IFNE    NARG-1
  59.         FAIL    arguments "ret"
  60.     ENDC
  61.         move.w    #$4e75,\1
  62.     ENDM
  63.  
  64. ****************************************************************
  65. ***** skip \1 instruction bytes on address \2
  66. skip    MACRO
  67.     IFNE    NARG-2
  68.         FAIL    arguments "skip"
  69.     ENDC
  70.     IFLE \1-126
  71.         move.w    #$6000+\1-2,\2
  72.     ELSE
  73.     IFLE \1-32766
  74.         move.l    #$60000000+\1-2,\2
  75.     ELSE
  76.         FAIL    "skip: distance to large"
  77.     ENDC
  78.     ENDC
  79.     ENDM
  80.  
  81. ****************************************************************
  82. ***** write \1 times opcode NOP starting at address \2
  83. ***** (better to use "skip" instead)
  84. nops    MACRO
  85.     IFNE    NARG-2
  86.         FAIL    arguments "nops"
  87.     ENDC
  88.         movem.l    d0/a0,-(a7)
  89.         IFGT \1-127
  90.             move.w    #\1-1,d0
  91.         ELSE
  92.             moveq    #\1-1,d0
  93.         ENDC
  94.         lea    \2,a0
  95. .lp\@        move.w    #$4e71,(a0)+
  96.         dbf    d0,.lp\@
  97.         movem.l    (a7)+,d0/a0
  98.     ENDM
  99.  
  100. ****************************************************************
  101. ***** write opcode JMP \2 to address \1
  102. patch    MACRO
  103.     IFNE    NARG-2
  104.         FAIL    arguments "patch"
  105.     ENDC
  106.         move.w    #$4ef9,\1
  107.         pea    (\2,pc)
  108.         move.l    (a7)+,2+\1
  109.     ENDM
  110.  
  111. ****************************************************************
  112. ***** write opcode JSR \2 to address \1
  113. patchs    MACRO
  114.     IFNE    NARG-2
  115.         FAIL    arguments "patchs"
  116.     ENDC
  117.         move.w    #$4eb9,\1
  118.         pea    (\2,pc)
  119.         move.l    (a7)+,2+\1
  120.     ENDM
  121.  
  122. ****************************************************************
  123. ***** wait that blitter has finished his job
  124. ***** (this is adapted from graphics.WaitBlit, see autodocs for
  125. *****  hardware bugs and caveats)
  126. ***** if \1 is given it must be an address register containing _custom
  127. BLITWAIT MACRO
  128.     IFEQ    NARG-1
  129.         tst.b    (dmaconr,\1)
  130. .waitb\@    tst.b    (_ciaa)        ;this avoids blitter slow down
  131.         tst.b    (_ciaa)
  132.         btst    #DMAB_BLTDONE-8,(dmaconr,\1)
  133.         bne.b    .waitb\@
  134.         tst.b    (dmaconr,\1)
  135.     ELSE
  136.         tst.b    (_custom+dmaconr)
  137. .waitb\@    tst.b    (_ciaa)        ;this avoids blitter slow down
  138.         tst.b    (_ciaa)
  139.         btst    #DMAB_BLTDONE-8,(_custom+dmaconr)
  140.         bne.b    .waitb\@
  141.         tst.b    (_custom+dmaconr)
  142.     ENDC
  143.     ENDM
  144.  
  145. ****************************************************************
  146. ***** wait of vertical blank
  147. ***** if \1 is given it must be an address register containing _custom
  148. waitvb    MACRO
  149.     IFEQ    NARG-1
  150. .1\@        btst    #0,(vposr+1,\1)
  151.         beq    .1\@
  152. .2\@        btst    #0,(vposr+1,\1)
  153.         bne    .2\@
  154.     ELSE
  155. .1\@        btst    #0,(_custom+vposr+1)
  156.         beq    .1\@
  157. .2\@        btst    #0,(_custom+vposr+1)
  158.         bne    .2\@
  159.     ENDC
  160.     ENDM
  161.  
  162. ****************************************************************
  163. ***** wait for pressing any button
  164. ***** if \1 is given it must be an address register containing _custom
  165. waitbutton    MACRO
  166.     IFEQ    NARG
  167.         move.l    a0,-(a7)
  168.         lea    (_custom),a0
  169. .down\@        bsr    .wait\@
  170.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  171.         beq    .up\@
  172.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  173.         beq    .up\@
  174.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  175.         bne    .down\@
  176. .up\@        bsr    .wait\@                    ;entprellen
  177.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  178.         beq    .up\@
  179.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  180.         beq    .up\@
  181.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  182.         beq    .up\@
  183.         bsr    .wait\@                    ;entprellen
  184.         bra    .done\@
  185. .wait\@        waitvb    a0
  186.         rts
  187. .done\@        move.l    (a7)+,a0
  188.     ELSE
  189.     IFEQ    NARG-1
  190. .down\@        bsr    .wait\@
  191.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  192.         beq    .up\@
  193.         btst    #POTGOB_DATLY-8,(potinp,\1)        ;RMB
  194.         beq    .up\@
  195.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  196.         bne    .down\@
  197. .up\@        bsr    .wait\@                    ;entprellen
  198.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  199.         beq    .up\@
  200.         btst    #POTGOB_DATLY-8,(potinp,\1)        ;RMB
  201.         beq    .up\@
  202.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  203.         beq    .up\@
  204.         bsr    .wait\@                    ;entprellen
  205.         bra    .done\@
  206. .wait\@        waitvb    \1
  207.         rts
  208. .done\@
  209.     ELSE
  210.         FAIL    arguments "waitbutton"
  211.     ENDC
  212.     ENDC
  213.     ENDM
  214.  
  215. waitbuttonup    MACRO
  216.     IFEQ    NARG
  217.         move.l    a0,-(a7)
  218.         lea    (_custom),a0
  219. .up\@        bsr    .wait\@                    ;entprellen
  220.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  221.         beq    .up\@
  222.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  223.         beq    .up\@
  224.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  225.         beq    .up\@
  226.         bsr    .wait\@                    ;entprellen
  227.         bra    .done\@
  228. .wait\@        waitvb    a0
  229.         rts
  230. .done\@        move.l    (a7)+,a0
  231.     ELSE
  232.     IFEQ    NARG-1
  233. .up\@        waitvb    \1                    ;entprellen
  234.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  235.         beq    .up\@
  236.         btst    #POTGOB_DATLY-8,(potinp,\1)        ;RMB
  237.         beq    .up\@
  238.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  239.         beq    .up\@
  240.         waitvb    \1                    ;entprellen
  241.     ELSE
  242.         FAIL    arguments "waitbuttonup"
  243.     ENDC
  244.     ENDC
  245.     ENDM
  246.  
  247. ****************************************************************
  248. ***** flash the screen and wait for LMB
  249. blitz        MACRO
  250.         move    #$4200,bplcon0+_custom
  251.     ;    move    #DMAF_SETCLR!DMAF_RASTER,dmacon+_custom
  252.         move.l    d0,-(a7)
  253. .lpbl\@        move.w    d0,$dff180
  254.         subq.w    #1,d0
  255.         btst    #6,$bfe001
  256.         bne    .lpbl\@
  257.         waitvb                    ;entprellen
  258.         waitvb                    ;entprellen
  259. .lp2bl\@    move.w    d0,$dff180
  260.         subq.w    #1,d0
  261.         btst    #6,$bfe001
  262.         beq    .lp2bl\@
  263.         waitvb                    ;entprellen
  264.         waitvb                    ;entprellen
  265.         clr.w    color+_custom
  266.         move.l    (a7)+,d0
  267.         ENDM
  268.  
  269. ****************************************************************
  270. ***** color the screen and wait for LMB
  271. bwait        MACRO
  272.         move    #$1200,bplcon0+_custom
  273. .wd\@
  274.     IFEQ NARG
  275.         move.w    #$ff0,color+_custom        ;yellow
  276.     ELSE
  277.         move.w    #\1,color+_custom
  278.     ENDC
  279.         btst    #6,$bfe001
  280.         bne    .wd\@
  281.         waitvb                    ;entprellen
  282.         waitvb                    ;entprellen
  283. .wu\@        btst    #6,$bfe001
  284.         beq    .wu\@
  285.         waitvb                    ;entprellen
  286.         waitvb                    ;entprellen
  287.         clr.w    color+_custom
  288.         ENDM
  289.  
  290. ****************************************************************
  291. ***** install Vertical-Blank-Interrupt which quits on LMB pressed
  292. QUITVBI        MACRO
  293.         move.l    a0,-(a7)
  294.         lea    (.vbi,pc),a0
  295.         move.l    a0,$6c
  296.         bra    .g
  297. .vbi        btst    #6,$bfe001
  298.         beq    .vbi+1        ;create "address error"
  299.         move.w    #INTF_VERTB,_custom+intreq
  300.         rte
  301. .g        move.w    #INTF_SETCLR!INTF_INTEN!INTF_VERTB,_custom+intena
  302.         move.w    #INTF_VERTB,_custom+intreq
  303.         move.l    (a7)+,a0
  304.     ENDM
  305.  
  306. ****************************************************************
  307. ***** set all registers to zero
  308. resetregs    MACRO
  309.         moveq    #0,d0
  310.         moveq    #0,d1
  311.         moveq    #0,d2
  312.         moveq    #0,d3
  313.         moveq    #0,d4
  314.         moveq    #0,d5
  315.         moveq    #0,d6
  316.         moveq    #0,d7
  317.         sub.l    a0,a0
  318.         sub.l    a1,a1
  319.         sub.l    a2,a2
  320.         sub.l    a3,a3
  321.         sub.l    a4,a4
  322.         sub.l    a5,a5
  323.         sub.l    a6,a6
  324.     ENDM
  325.  
  326. ;=============================================================================
  327.  
  328.  ENDC
  329.